package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.aop.Logging;
import com.briup.jd2407cms.domain.DTO.LoginParam;
import com.briup.jd2407cms.domain.User;
import com.briup.jd2407cms.service.LoginService;
import com.briup.jd2407cms.service.UserService;
import com.briup.jd2407cms.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: JD2407-cms
 * @BelongsPackage: com.briup.jd2407cms.web.controller
 * @Author: 鲨鲨天下第一
 * @CreateTime: 2024-11-19  09:04
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "登录模块")
@Slf4j
@RestController
public class LoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "用户登录", notes = "需要提供用户名和密码")
    @Logging("用户登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginParam param){
        return Result.success(loginService.login(param));
    }

    @ApiOperation(value = "用户登录", notes = "需要提供用户名和密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", paramType = "form", dataType = "String", required = true,
                    defaultValue = "admin"),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "form", dataType = "String", required = true,
                    defaultValue = "admin")
    }) //Post请求 + form提交 + consumes设置表单字符串
    @Logging("")
    @PostMapping(value = "/login_old", consumes = "application/x-www-form-urlencoded")
    public Result login(String username, @RequestParam("password") String password) {
        User user = userService.prelogin(username, password);
        return Result.success(user);
    }

    @ApiOperation(value = "用户登出，退出登录")
    @Logging("用户登出")
    @PostMapping(value = "/logout")
    public Result logout(){
        return Result.success();
    }

}
